﻿using System;
using System.ComponentModel;

namespace JumpingBalls.AppCode
{
    public class GameContext : INotifyPropertyChanged
    {
        public const int BallsCount = 5;

        public const int GroundLength = 9;

        public event Action<int, int, int, bool> OnGroundValueChange;

        private bool isRunging;

        public bool IsRuning
        {
            get { return isRunging; }
            set
            {
                isRunging = value;

                NotifyPropertyChanged("IsRuning");
            }
        }

        private int score;

        public int Score
        {
            get { return score; }
            set
            {
                score = value;
                NotifyPropertyChanged("Score");
            }
        }

        private int nextBall1;

        public int NextBall1
        {
            get { return nextBall1; }
            set
            {
                nextBall1 = value;
                NotifyPropertyChanged("NextBall1");
            }
        }

        private int nextBall2;

        public int NextBall2
        {
            get { return nextBall2; }
            set
            {
                nextBall2 = value;
                NotifyPropertyChanged("NextBall2");
            }
        }

        private int nextBall3;

        public int NextBall3
        {
            get { return nextBall3; }
            set
            {
                nextBall3 = value;
                NotifyPropertyChanged("NextBall3");
            }
        }

        private int[][] ground;

        public int[][] Ground
        {
            get { return ground; }
            set
            {
                ground = value;
                NotifyPropertyChanged("Ground");
            }
        }

        private int blockLeft;

        public int BlockLeft
        {
            get { return blockLeft; }
            set
            {
                blockLeft = value;
                NotifyPropertyChanged("BlockLeft");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String propertyName)
        {
            if (null != PropertyChanged)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public void ChangeValue(int row, int col, int value, bool isEraseBall)
        {
            Ground[row][col] = value;
            OnGroundValueChange.Invoke(row, col, value, isEraseBall);
        }
    }
}
